﻿///<reference path="../../../../Scripts/jquery-1.4.1-vsdoc.js"/>
///<reference path="../utils/Utils.js"/>


function TreeViewItem(id, title, cssClass, onClick, closed) {

    this.Id = id;
    this.Title = title;
    this.Class = cssClass;
    this.OnClick = onClick;
    this.Items = [];
    this.ParentControl;
    this.Closed = closed;

    this.AddItem = function (id, title, cssClass, onClick, closed) {
        return this.Items[this.Items.push(new TreeViewItem(id, title, cssClass, onClick, closed)) - 1];
    }   

    this.ToHtml = function() {
        var resultString = "<li";

        if (this.Closed != undefined && this.Closed)
            resultString += " class='closed'";

        resultString += "><span class='" + this.Class + "'";

        if (this.Id != undefined && this.Id != '')
            resultString += " id='" + this.Id + "'";
        
        if (this.OnClick != undefined && this.OnClick != '')
            resultString += " onclick='" + this.OnClick + "'";
        
        resultString += ">" + this.Title + "</span>";

        if (this.Items.length > 0)
        {
            resultString += "<ul>";        

            for(var i = 0; i< this.Items.length; i++)
            {
                resultString += this.Items[i].ToHtml();
            }

            resultString += "</ul>";
        }

        return resultString + "</li>";
    }  
}

function TreeViewBase(id, parentControl) {

    this.Id = id;
    this.Items = [];
    this.ParentControl = parentControl;

    this.AddItem = function (id, title, cssClass, onClick, closed) {
        return this.Items[this.Items.push(new TreeViewItem(id, title, cssClass, onClick, closed)) - 1];
    }   

    this.ToHtml = function() {
        var resultString = "<ul id='" + this.Id + "' class='filetree'>";

        for(var i = 0; i< this.Items.length; i++)
        {
            resultString += this.Items[i].ToHtml();
        }   

        return resultString + "</ul>";
    }    

    this.Render = function() {
        this.ParentControl.append(this.ToHtml());

        $("#" + this.Id).treeview({
                animated: "fast",
                collapsed: true
            });
    }

    this.SelectItem = function(id) {
        
    }
}